import java.awt.Image;
import javax.swing.ImageIcon;
import java.util.Random;


public class Enemies {

    private int  y;
    private double initialX, x;
    private Image image;
    private boolean visible;
    private double speed = 0.5;
    private boolean movingRight, moving;
    
    public Enemies(double x, int y) {
    	
    	//Creates and new enemy object, has position and 
    	//is represented by an ImageIcon (which are double buffered)
        ImageIcon ii = new ImageIcon("Enemy.png", "Enemy");
        image = ii.getImage();
        visible = true;
        this.x = x;
        initialX = x;
        this.y = y;
        
        
		moving = false;
    }

    public Enemies(double x, int y, boolean movingRight) {
    	
    	//Creates and new enemy object again but this time it will move on the x axis
        ImageIcon ii = new ImageIcon("Enemy.png", "Enemy");
        image = ii.getImage();
        visible = true;
        this.x = x;
        initialX = x;
        this.y = y;
        
        	moving = true;
			this.movingRight = movingRight;
		
 
    }

    //Basic getter methods
    public Image getImage() {
        return image;
    }

    public int getX() {
        return (int) x;
    }

    public int getY() {
        return y;
    }

    public boolean isVisible() {
        return visible;
    }
    
    public double getSpeed()
    {
    	return speed;
    }
    
    //Changes the speed of the enemy object, this will be called
    //whenever the the player reaches a certain place on the board
    public void changeSpeed(int speed)
    {
    	this.speed =speed;
    }


    //Will be called before the enemy is drawn, unless the 
    //enemy is no longer visible on the board
    public void move() {
    	
    	if(moving)
    	{
    		if(initialX == x)
    		{
    			x = initialX + 1;
    		}
    		else if(movingRight)
    		{
    			if((x + 0.1 > (initialX + 100)))
    			{
    					movingRight = false;
    			}
    			else
    			{
    				x = x + 0.2;
    			}
    		}
    		else
    		{
    			if((x - 0.1 < (initialX - 100)))
    			{
    					movingRight = true;
    			}
    			else
    			{
    				x= x - 0.3;
    			}
    		}
    	}
    	
        y -= speed;
        if (y < -100)
            visible = false;
    }
}